// pages/kill_detail/kill_detail.js
var common = require("../../../common/common.js").common;

var leader = require("../../../common/leader.js").leader;

var WxParse = require("../../../wxParse/wxParse.js");

var app = getApp();

var {$author: $author} = require("../../../components/base/authorization.js");

var un = require("../../../siteinfo.js");

var util = require("../../../utils/util.js");

Page({
    /**
   * 页面的初始数据
   */
    data: {
        pagesLength: 1,
        //仅有一页，不显示返回按钮
        showInfoTip: false,
        //授权失败的弹框
        currentSwiper: 0,
        alert1: 0,
        alert: 0,
        close: 1,
        details: [],
        price: "",
        sku: "",
        buy_count: 1,
        sku_info: "",
        cart: [],
        product_id: 0,
        cart_count: 0,
        pid: "",
        goods: [],
        index_msg: [],
        detail: "",
        // setInterval: '',
        btn_true: 1,
        leader_id: "",
        warrant: true,
        custom_attributes_show: 0,
        color_header: "",
        color_main: "",
        color_minor: "",
        rich: "",
        details2: "",
        chooseCity: 0,
        options: "",
        s_leader: [],
        leader_id_share: "",
        chooseCity2: 0,
        nowCity: "",
        myleaderinfo: "",
        goodsId: "",
        isIPX: "",
        timeId: "",
        kill_hour: 0,
        kill_minute: 0,
        kill_second: 0,
        on_off_trans_free: 0,
        trans_for_free_barrier: 0,
        leaderChange: false,
        //团长切换弹窗显示隐藏，false为隐藏
        currentLeaderInfo: {},
        //当前团长信息
        modalHide: true,
        //提示框显示隐藏，true影藏
        tmplIds: [],
        //模板消息tmplIds
        subscribeMessage: true,
        killPoster: false
    },
    /** 
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        this.getHeader();
        wx.showShareMenu({
            // withShareTicket: true,
            menus: [ "shareAppMessage", "shareTimeline" ]
        });
        let pagesLength = getCurrentPages().length;
        var isIPX = app.globalData.isIPX;
        console.log("isIPX:" + isIPX);
        this.setData({
            isIPX: isIPX,
            pagesLength: pagesLength,
            domain: app.globalData.domain.slice(0, -10)
        });
        let that = this;
        clearInterval(that.data.timer);
        //解析分享二维码和分享首页的数据scene
                var scene = decodeURIComponent(options.scene);
        var s_leader = scene.split(":");
        that.setData({
            options: options,
            s_leader: s_leader,
            s_uid: s_leader[7],
            start_at: s_leader[9] + ":" + s_leader[10] + ":" + s_leader[11],
            h: s_leader[9],
            m: s_leader[10],
            s: s_leader[11]
        });
        //解析商品id  从页面点击传 id  二维码为scene的[3]
                var goodsId;
        var timeId;
        var start_at;
        var h;
        var m;
        var s;
        if (options.id && options.timeId && options.start_at) {
            goodsId = options.id;
            timeId = options.timeId;
            start_at = options.start_at;
            h = start_at.split(":")[0];
            m = start_at.split(":")[1];
            s = start_at.split(":")[2];
            that.setData({
                start_at: start_at,
                h: h,
                m: m,
                s: s
            });
        } else {
            goodsId = s_leader[3];
            timeId = s_leader[5];
            var s_uid = s_leader[7];
            that.setData({
                s_uid: s_uid
            });
        }
        that.setData({
            goodsId: goodsId,
            timeId: timeId
        });
        wx.getSystemInfo({
            success: function(res) {
                let rpx = res.windowWidth / 375;
                that.setData({
                    rpx: rpx
                });
            }
        });
        //首次直接进入，拿openid
                if (app.globalData.user) {
            //如果直接拿到openid
            that.setData({
                uid: app.globalData.user.uid
            });
            that.requestStart(app.globalData.user.openid);
        } else {
            //回调拿到openid
            app.userInfoReadyCallback = (res => {
                that.setData({
                    uid: res.uid
                });
                that.requestStart(res.openid);
            });
        }
        if (options && options.onshare && options.onshare == 1) {
            that.requestStart();
        }
        that.getTmplIds();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {
        common.getCart();
    },
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {
        console.log("隐藏了，要重置定时器");
        clearInterval(this.data.timer);
    },
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {
        this.requestStart();
        wx.stopPullDownRefresh();
    },
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {},
    onShareTimeline: function() {
        let that = this;
        var details = that.data.details;
        var product_id = that.data.product_id;
        var timeId = that.data.timeId;
        var my_leaderID = this.data.myleaderinfo.leader_id;
        var shareImgUrl = that.data.shareImgUrl;
        var start_at = that.data.start_at;
        var share_link = that.data.share_link;
        return {
            title: that.data.details.name,
            imageUrl: that.data.details.icon,
            // 图片 URL
            query: "onshare=1&scene=" + that.data.pro_id + encodeURIComponent("l:" + my_leaderID + ":p:" + product_id + ":timeId:" + timeId + ":start_at:" + start_at)
        };
    },
    //获取去右侧胶囊的信息
    getHeader() {
        let menuRect = wx.getMenuButtonBoundingClientRect();
        this.setData({
            topBarHeight: menuRect.height,
            topBarTop: menuRect.top,
            topBarWidth: menuRect.width
        });
    },
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {
        var that = this;
        var code = wx.getStorageSync("code");
        this.setData({
            alert1: 0
        });
        var details = that.data.details;
        var product_id = that.data.product_id;
        var timeId = that.data.timeId;
        var my_leaderID = this.data.myleaderinfo.leader_id;
        var shareImgUrl = that.data.shareImgUrl;
        var start_at = that.data.start_at;
        var share_link = that.data.share_link;
        if (share_link == 2) {
            return {
                title: details.name,
                // imageUrl: that.data.share_type == 1 ? that.data.shareCanvasPhoto : shareImgUrl,
                imageUrl: that.data.shareCanvasPhoto,
                path: "/pages/index/index?uid=" + that.data.uid + "&pro_id=" + product_id + "&time_id=" + timeId + "&start_at=" + start_at
            };
        } else {
            return {
                title: details.name,
                // imageUrl: that.data.share_type == 1 ? that.data.shareCanvasPhoto : shareImgUrl,
                imageUrl: that.data.shareCanvasPhoto,
                path: "/kill/pages/kill_detail/kill_detail?scene=" + encodeURIComponent("l:" + my_leaderID + ":p:" + product_id + ":timeId:" + timeId + ":uid:" + that.data.uid + ":start_at:" + start_at)
            };
        }
    },
    makeWxapp_img: function(ctx, options) {
        let that = this;
        let name = that.data.title;
        let nameLen = name.length;
        let titleLen = 32.5 + nameLen * 16;
        ctx.drawImage(that.data.domain + "/img/mainPack/share_title.png", (250 - titleLen) * that.data.rpx, 0, (titleLen + 60) * that.data.rpx, 30 * that.data.rpx);
        //图片加载完成 
                if (that.data.wxapp_img) {
            let wxapp_img = that.data.wxapp_img;
            if (wxapp_img.indexOf("https:") < 0) {
                wxapp_img = wxapp_img.replace("http:", "https:");
            }
            wx.getImageInfo({
                src: wxapp_img,
                success: function(res) {
                    ctx.save();
                    ctx.beginPath();
                    //开始绘制
                                        ctx.arc((260 - titleLen + 30) * that.data.rpx, 15 * that.data.rpx, 10 * that.data.rpx, 0, Math.PI * 2, false);
                    ctx.clip();
                    ctx.drawImage(res.path, (260 - titleLen + 20) * that.data.rpx, 5 * that.data.rpx, 20 * that.data.rpx, 20 * that.data.rpx);
                    ctx.restore();
                    options.callback();
                },
                fail(res) {
                    options.callback();
                }
            });
        } else {
            options.callback();
        }
    },
    goBack() {
        let that = this;
        let pages = getCurrentPages();
        let prevPage = pages[pages.length - 2];
        wx.navigateBack({});
    },
    //*******************************************************
    //
    // 整理合并产品页所有请求 hgj 2019.11.04 
    // 下面为封装的共用方法调用
    //
    //*******************************************************
    //首页弹窗
    getUserInfo: function() {
        common.getUserInfo();
    },
    //团长切换共用方法调用
    chooseButt: function(e) {
        leader.chooseButt(e);
    },
    //页面请求开始
    requestStart: function(openid) {
        let that = this;
        if (that.data.s_uid) {
            that.levelShare();
        }
        leader.getMyLeaderInfo(openid, that.data.s_leader[1]);
        //公用方法团长请求
                that.getBase(openid);
        //基础配置
        //产品详情相关信息
                that.getData(1);
    },
    //全局基础配置信息
    getBase: function(openid) {
        var that = this;
        common.request({
            endpoint: "set/app_base",
            method: "get",
            data: {},
            success: res => {
                if (res.extra.copyright_msg) {
                    var copy = res.extra.copyright_msg;
                    var copyText = [];
                    if (copy.indexOf(",") != -1) {
                        copyText = copy.split(",");
                    } else {
                        copyText[0] = copy;
                    }
                } else {
                    copyText = "";
                }
                wx.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor: res.extra.color_main
                });
                that.setData({
                    color_main: res.extra.color_main,
                    color_minor: res.extra.color_minor,
                    title: res.extra.title,
                    style: res.extra.style,
                    leader_change: res.extra.l_change,
                    phone: res.extra.phone,
                    rp_name: res.extra.rp_name,
                    leaderName: res.extra.leader_title ? res.extra.leader_title : "团长",
                    lock_fans: res.extra.lock_fans,
                    share_link: res.extra.share_link,
                    share_type: res.extra.share_type,
                    wxapp_img: res.extra.wxapp_img,
                    new_member_audit: res.extra.new_member_audit,
                    userAuditStatus: res.extra.userAuditStatus ? res.extra.userAuditStatus : 2,
                    custom_title: res.extra.level_set.custom_title
                });
            }
        });
    },
    /**
   * 分销商绑定上下级
   */
    levelShare: function() {
        let that = this;
        common.request({
            endpoint: "Level/level/level-share",
            method: "post",
            data: {
                user_id: that.data.s_uid
            },
            success: res => {
                if (that.data.level_set.success_bind_tip) {
                    wx.showToast({
                        icon: "none",
                        title: that.data.level_set.success_bind_tip
                    });
                } else {
                    wx.showToast({
                        icon: "none",
                        title: "绑定成功"
                    });
                }
            },
            fail(err) {}
        });
    },
    //主数据
    getData: function(getDataMore) {
        var that = this;
        var id = that.data.goodsId;
        var time_id = that.data.timeId;
        common.request({
            //endpoint: 'product/product_info',
            endpoint: "product/product_detail",
            method: "post",
            data: {
                id: id,
                visit_type: 1,
                time_id: time_id
            },
            success: res => {
                console.log(res.extra);
                let details = res.extra;
                let custom_attributes_show = 0;
                for (var i = 0; i < details.custom_attributes.length; i++) {
                    if (details.custom_attributes[i]["show"] == 1) {
                        custom_attributes_show++;
                    }
                }
                details.sku_attribute = details.sku_attribute.map(item => {
                    item.attribute_value = this.selectSingleSku(item.attribute_value);
                    return item;
                });
                let sku_attribute = details.sku_attribute;
                let sku = sku_attribute.reduce((s, v) => {
                    s = this.reBlanceSku(s, parseInt(v.attribute_key.id), parseInt(v.attribute_value[0].id));
                    return s;
                }, "");
                let sku_info = this.getProductBySku(details.sku, sku);
                that.setData({
                    custom_attributes_show: custom_attributes_show,
                    details: details,
                    sku: sku,
                    product_id: id,
                    sku_info: sku_info,
                    flag: details.timing_flag
                });
                if (details.timing_flag == -1) {
                    wx.showToast({
                        title: "秒杀已结束",
                        icon: "none",
                        duration: 2e3
                    });
                } else {
                    clearInterval(that.data.timer);
                    that.kill_countdown(details.timing);
                }
                that.getDetail();
                //在请求产品的描述                        ----------这个也是
                                that.getKillShareImg(details.timing_flag);
            }
        });
    },
    //产品详情富文本 和 邻居都在买产品
    getDetail: function() {
        var that = this;
        var id = that.data.goodsId;
        common.request({
            //endpoint: 'product/product_info',
            endpoint: "product/product_detail",
            method: "post",
            data: {
                id: id,
                visit_type: 2
            },
            success: res => {
                let details = res.extra;
                that.setData({
                    detail: WxParse.wxParse("detail", "html", details.detail, that, 0),
                    rich: WxParse.wxParse("rich", "html", details.rich, that, 0)
                });
            }
        });
    },
    //点击分享
    alert_send: function() {
        var alert1 = this.data.alert1;
        if (alert1 == 0) {
            alert1 = 1;
        } else {
            alert1 = 0;
        }
        this.setData({
            alert1: alert1
        });
    },
    //秒杀倒计时
    kill_countdown: function(times) {
        var that = this;
        clearInterval(that.data.timer);
        var timer = null;
        that.setData({
            timer: setInterval(() => {
                var day = 0, hour = 0, minute = 0, second = 0;
                if (times > 0) {
                    hour = Math.floor(times / (60 * 60)) - day * 24;
                    minute = Math.floor(times / 60) - day * 24 * 60 - hour * 60;
                    second = Math.floor(times) - day * 24 * 60 * 60 - hour * 60 * 60 - minute * 60;
                }
                if (hour <= 9) hour = "0" + hour;
                if (minute <= 9) minute = "0" + minute;
                if (second <= 9) second = "0" + second;
                that.setData({
                    kill_hour: hour,
                    kill_minute: minute,
                    kill_second: second
                });
                if (hour == 0 && minute == 0 && second == 0 && (that.data.details.timing_flag == 0 || that.data.details.timing_flag == 1)) {
                    clearInterval(that.data.timer);
                    that.getData();
                } else {
                    times--;
                }
            }, 1e3)
        });
        if (times <= 0) {
            clearInterval(that.data.timer);
        }
    },
    /**
   * 获取秒杀分享图-后端生成
   */
    getKillShareImg_backstage(flag) {
        let that = this;
        var details = that.data.details;
        switch (flag) {
          case 1:
            common.request({
                endpoint: "share/poster_second",
                method: "post",
                data: {
                    name: details.name,
                    price: details.low_price,
                    original_price: details.low_oprice,
                    id: details.id,
                    time_id: that.data.timeId
                },
                success(res) {
                    if (util.compareVersion(un.version, "2.4.20") < 0) {
                        that.setData({
                            shareImgUrl: JSON.parse(res).extra.image[0].url
                        });
                    } else {
                        that.setData({
                            shareImgUrl: res.extra.url
                        });
                    }
                }
            });
            break;

          case 0:
            common.request({
                endpoint: "share/poster_third",
                method: "post",
                data: {
                    name: details.name,
                    price: details.low_price,
                    original_price: details.low_oprice,
                    id: details.id,
                    time_id: that.data.timeId
                },
                success(res) {
                    if (util.compareVersion(un.version, "2.4.20") < 0) {
                        that.setData({
                            shareImgUrl: JSON.parse(res).extra.image[0].url
                        });
                    } else {
                        that.setData({
                            shareImgUrl: res.extra.url
                        });
                    }
                }
            });
            break;
        }
    },
    /**
   * 获取秒杀分享图-前端生成
   */
    getKillShareImg(flag) {
        let that = this;
        var details = that.data.details;
        var kill_share_title = "", kill_share_btn = "", kill_share_time = "", tip = "", bg_color1 = "", bg_color2 = "";
        if (flag == 1) {
            tip = "距离结束";
            kill_share_title = that.data.domain + "/img/mainPack/kill_share_title.png";
            kill_share_btn = that.data.domain + "/img/mainPack/kill_share_btn.png";
            kill_share_time = that.data.domain + "/img/mainPack/kill_share_time.png";
            bg_color1 = "#FFF6F5";
            bg_color2 = "#FFA196";
        } else if (flag == 0) {
            tip = "距离开始";
            kill_share_title = that.data.domain + "/img/mainPack/kill_share_title.png";
            kill_share_btn = that.data.domain + "/img/mainPack/kill_share_btn1.png";
            kill_share_time = that.data.domain + "/img/mainPack/kill_share_time1.png";
            bg_color1 = "#E1F6D1";
            bg_color2 = "#FFF6F5";
        }
        const ctx = wx.createCanvasContext("shareCanvas");
        let carousel = that.data.details.carousel_img[0];
        if (carousel.indexOf("https:") < 0) {
            carousel = carousel.replace("http:", "https:");
        }
        ctx.setFillStyle(bg_color1);
        ctx.fillRect(0 * that.data.rpx, 0 * that.data.rpx, 300 * that.data.rpx, 240 * that.data.rpx);
        ctx.setFillStyle("#fff");
        ctx.fillRect(12 * that.data.rpx, 24 * that.data.rpx, 274 * that.data.rpx, 176 * that.data.rpx);
        ctx.setLineWidth = 2 * that.data.rpx;
        ctx.setStrokeStyle(bg_color2);
        ctx.strokeRect(12 * that.data.rpx, 24 * that.data.rpx, 274 * that.data.rpx, 176 * that.data.rpx);
        wx.getImageInfo({
            src: carousel,
            success: function(res) {
                ctx.drawImage(res.path, 25.5 * that.data.rpx, 40.5 * that.data.rpx, 124 * that.data.rpx, 124 * that.data.rpx);
                ctx.drawImage(kill_share_title, 178 * that.data.rpx, 35 * that.data.rpx, 62.5 * that.data.rpx, 22.5 * that.data.rpx);
                ctx.strokeStyle = "#E1E1E1";
                ctx.setLineWidth = 2 * that.data.rpx;
                ctx.moveTo(158.5 * that.data.rpx, 62.5 * that.data.rpx);
                ctx.lineTo(272 * that.data.rpx, 62.5 * that.data.rpx);
                ctx.stroke();
                that.dealWords({
                    ctx: ctx,
                    font: "normal bold 14px YaHei",
                    FillStyle: "#666",
                    word: that.data.details.name,
                    maxWidth: 106 * that.data.rpx,
                    x: 160 * that.data.rpx,
                    y: 60 * that.data.rpx,
                    maxLine: 2
                });
                ctx.fillStyle = "#F33E33";
                ctx.font = "12px YaHei";
                ctx.fillText("￥", 160 * that.data.rpx, 125 * that.data.rpx);
                ctx.font = "normal bold 21px YaHei";
                ctx.fillText(that.data.details.low_price, 170 * that.data.rpx, 125 * that.data.rpx);
                ctx.fillStyle = "#ccc";
                ctx.font = "12px YaHei";
                ctx.fillText("￥" + that.data.details.low_oprice, 160 * that.data.rpx, 152 * that.data.rpx);
                var low_oprice_width = ctx.measureText("￥" + that.data.details.low_oprice).width;
                ctx.strokeStyle = "#ccc";
                ctx.setLineWidth = 2 * that.data.rpx;
                ctx.moveTo(160 * that.data.rpx, 147 * that.data.rpx);
                ctx.lineTo((160 + low_oprice_width) * that.data.rpx, 147 * that.data.rpx);
                ctx.stroke();
                ctx.drawImage(kill_share_btn, 202 * that.data.rpx, 141 * that.data.rpx, 72 * that.data.rpx, 26.2 * that.data.rpx);
                ctx.drawImage(kill_share_time, 12 * that.data.rpx, 205 * that.data.rpx, 274 * that.data.rpx, 33 * that.data.rpx);
                ctx.fillStyle = "#fff";
                ctx.font = "12px YaHei";
                let times = that.data.details.timing;
                var day = 0, hour = 0, minute = 0, second = 0;
                //时间默认值
                                hour = Math.floor(times / (60 * 60)) - day * 24;
                minute = Math.floor(times / 60) - day * 24 * 60 - hour * 60;
                second = Math.floor(times) - day * 24 * 60 * 60 - hour * 60 * 60 - minute * 60;
                if (hour <= 9) hour = "0" + hour;
                if (minute <= 9) minute = "0" + minute;
                if (second <= 9) second = "0" + second;
                ctx.fillText(tip + hour + ":" + minute + ":" + second, 100 * that.data.rpx, 225 * that.data.rpx);
                ctx.draw(true, () => {
                    wx.canvasToTempFilePath({
                        canvasId: "shareCanvas",
                        fileType: "png",
                        success: function(res) {
                            that.setData({
                                shareCanvasPhoto: res.tempFilePath
                            });
                        },
                        fail: function(res) {},
                        complete: function(res) {}
                    }, that);
                });
            }
        });
    },
    makeposter: function() {
        let that = this;
        var my_leaderID = that.data.myleaderinfo.leader_id;
        const ctx = wx.createCanvasContext("firstCanvas");
        common.request({
            endpoint: "share/poster_read",
            method: "post",
            data: {
                lid: my_leaderID,
                id: that.data.details.id,
                time_id: that.data.timeId,
                uid: that.data.uid
            },
            success: res => {
                var res = JSON.parse(res);
                let poster_seckill = res.data.poster_seckill;
                let qc = res.data.qc;
                if (poster_seckill.indexOf("kgoods_bg") != -1) {
                    if (that.data.style == "1") {
                        //一列大图的缩略图
                        that.setData({
                            ["details.icon"]: that.data.details.carousel_img[0]
                        });
                    }
                    wx.navigateTo({
                        url: "/poster/pages/kill_detail_share/kill_detail_share?uid=" + that.data.uid + "&start_at=" + that.data.start_at + "&timeId=" + that.data.timeId + "&details=" + encodeURIComponent(JSON.stringify(that.data.details))
                    });
                } else {
                    that.makeposter_ch();
                }
            }
        });
    },
    /**
   * ctx
   * qc 商品二维码
   */
    killPost_type1: function(ctx, qc) {
        let that = this;
        let leaderinfo_title = that.data.myleaderinfo.title ? that.data.myleaderinfo.title : "-";
        let leaderinfo_name = that.data.myleaderinfo.name ? that.data.myleaderinfo.name : "-";
        let leaderinfo_other = that.data.myleaderinfo.other ? that.data.myleaderinfo.other : "-";
        let leaderinfo_img = that.data.myleaderinfo.other ? that.data.myleaderinfo.img : "/images/default.png";
        wx.getImageInfo({
            src: that.data.details.icon,
            success(res) {
                ctx.drawImage(res.path, 22 * that.data.rpx, 110 * that.data.rpx, 330 * that.data.rpx, 330 * that.data.rpx);
                that.dealWords({
                    ctx: ctx,
                    font: "normal bold 18px sans-serif",
                    FillStyle: "#333",
                    word: that.data.details.name,
                    maxWidth: 330 * that.data.rpx,
                    x: 25 * that.data.rpx,
                    y: 450 * that.data.rpx,
                    maxLine: 1
                });
                ctx.setFillStyle("#fe3112");
                ctx.font = "18px sans-serif";
                ctx.fillText("￥", 25 * that.data.rpx, 500 * that.data.rpx);
                ctx.setFillStyle("#fe3112");
                ctx.font = "20px sans-serif";
                ctx.fillText(that.data.details.low_price, 44 * that.data.rpx, 500 * that.data.rpx);
                ctx.drawImage(that.data.domain + "/img/mainPack/kill_icon.png", 100 * that.data.rpx, 480 * that.data.rpx, 68 * that.data.rpx, 20.5 * that.data.rpx);
                ctx.setFillStyle("#969696");
                ctx.font = "normal bold 10px sans-serif";
                ctx.fillText("￥", 25 * that.data.rpx, 520 * that.data.rpx);
                ctx.setFillStyle("#969696");
                ctx.font = "normal bold 12px sans-serif";
                ctx.fillText(that.data.details.low_oprice, 35 * that.data.rpx, 520 * that.data.rpx);
                ctx.beginPath();
                ctx.setStrokeStyle("#969696");
                ctx.setLineWidth(1.5 * that.data.rpx);
                ctx.moveTo(25 * that.data.rpx, 516 * that.data.rpx);
                ctx.lineTo(35 * that.data.rpx + ctx.measureText(that.data.details.low_oprice).width, 516 * that.data.rpx);
                ctx.stroke();
                ctx.closePath();
                ctx.setFillStyle("#ec2e08");
                ctx.font = "normal bold 12px sans-serif";
                ctx.fillText("开抢时间", 220 * that.data.rpx, 520 * that.data.rpx);
                ctx.setFillStyle("#464144");
                ctx.fillRect(280 * that.data.rpx, 505 * that.data.rpx, 20 * that.data.rpx, 20 * that.data.rpx);
                ctx.fill();
                ctx.setFillStyle("#fff");
                ctx.font = "12px sans-serif";
                ctx.fillText(that.data.start_at_h, 282 * that.data.rpx, 519 * that.data.rpx);
                ctx.setFillStyle("#464144");
                ctx.font = "12px sans-serif";
                ctx.fillText(":", 304 * that.data.rpx, 519 * that.data.rpx);
                ctx.setFillStyle("#464144");
                ctx.fillRect(312 * that.data.rpx, 505 * that.data.rpx, 18 * that.data.rpx, 18 * that.data.rpx);
                ctx.fill();
                ctx.setFillStyle("#fff");
                ctx.font = "12px sans-serif";
                ctx.fillText(that.data.start_at_m, 314 * that.data.rpx, 519 * that.data.rpx);
                ctx.setFillStyle("#464144");
                ctx.font = "12px sans-serif";
                ctx.fillText(":", 334 * that.data.rpx, 519 * that.data.rpx);
                ctx.setFillStyle("#ff5f4b");
                ctx.fillRect(342 * that.data.rpx, 505 * that.data.rpx, 18 * that.data.rpx, 18 * that.data.rpx);
                ctx.fill();
                ctx.setFillStyle("#fff");
                ctx.font = "12px sans-serif";
                ctx.fillText(that.data.start_at_s, 344 * that.data.rpx, 519 * that.data.rpx);
                ctx.setFillStyle("#fff");
                ctx.font = "normal bold 13px sans-serif";
                ctx.fillText(leaderinfo_name + "-" + leaderinfo_other, 25 * that.data.rpx, 580 * that.data.rpx);
                ctx.drawImage(that.data.domain + "/img/mainPack/address_icon.png", 22 * that.data.rpx, 597 * that.data.rpx, 9 * that.data.rpx, 11 * that.data.rpx);
                that.dealWords({
                    ctx: ctx,
                    font: "11px sans-serif",
                    FillStyle: "#fff",
                    word: leaderinfo_title,
                    maxWidth: 200 * that.data.rpx,
                    x: 35 * that.data.rpx,
                    y: 590 * that.data.rpx,
                    maxLine: 1
                });
                wx.getImageInfo({
                    src: qc,
                    success(res) {
                        ctx.arc(305 * that.data.rpx, 605 * that.data.rpx, 45 * that.data.rpx, 0, 2 * Math.PI);
                        ctx.setFillStyle("#fff");
                        ctx.fill();
                        ctx.drawImage(res.path, 260 * that.data.rpx, 560 * that.data.rpx, 90 * that.data.rpx, 90 * that.data.rpx);
                        ctx.draw(false, () => {
                            that.canvasToImage(ctx);
                        });
                    }
                });
            }
        });
    },
    killPost_type2: function(ctx, qc) {
        let that = this;
        let leaderinfo_title = that.data.myleaderinfo.title ? that.data.myleaderinfo.title : "-";
        let leaderinfo_name = that.data.myleaderinfo.name ? that.data.myleaderinfo.name : "-";
        let leaderinfo_other = that.data.myleaderinfo.other ? that.data.myleaderinfo.other : "-";
        let leaderinfo_img = that.data.myleaderinfo.other ? that.data.myleaderinfo.img : "/images/default.png";
        wx.getImageInfo({
            src: that.data.details.icon,
            success(res) {
                ctx.drawImage(res.path, 15 * that.data.rpx, 20 * that.data.rpx, 345 * that.data.rpx, 345 * that.data.rpx);
                ctx.drawImage(that.data.domain + "/img/mainPack/rect.png", 15 * that.data.rpx, 500 * that.data.rpx, 345 * that.data.rpx, 150 * that.data.rpx);
                that.dealWords({
                    ctx: ctx,
                    font: "normal bold 21px sans-serif",
                    FillStyle: "#333",
                    word: that.data.details.name,
                    maxWidth: 330 * that.data.rpx,
                    x: 20 * that.data.rpx,
                    y: 460 * that.data.rpx,
                    maxLine: 1
                });
                ctx.drawImage(that.data.domain + "/img/mainPack/kill_type.png", 15 * that.data.rpx, 340 * that.data.rpx, 345 * that.data.rpx, 90 * that.data.rpx);
                ctx.setFillStyle("#fff");
                ctx.font = "26px bold";
                ctx.fillText("开", 38 * that.data.rpx, 405 * that.data.rpx);
                ctx.fillText("始", 85 * that.data.rpx, 405 * that.data.rpx);
                ctx.fillText("时", 132 * that.data.rpx, 405 * that.data.rpx);
                ctx.fillText("间", 177 * that.data.rpx, 405 * that.data.rpx);
                ctx.fillText(that.data.start_at_h, 215 * that.data.rpx, 405 * that.data.rpx);
                ctx.fillText(that.data.start_at_m, 263 * that.data.rpx, 405 * that.data.rpx);
                ctx.fillText(that.data.start_at_s, 308 * that.data.rpx, 405 * that.data.rpx);
                wx.getImageInfo({
                    src: qc,
                    success(res) {
                        ctx.arc(75 * that.data.rpx, 565 * that.data.rpx, 50 * that.data.rpx, 0, 2 * Math.PI);
                        ctx.setFillStyle("#fff");
                        ctx.fill();
                        ctx.drawImage(res.path, 25 * that.data.rpx, 515 * that.data.rpx, 100 * that.data.rpx, 100 * that.data.rpx);
                        ctx.setFillStyle("#e93d3d");
                        ctx.font = "normal bold 14px sans-serif";
                        ctx.fillText("按住识别", 50 * that.data.rpx, 630 * that.data.rpx);
                        ctx.setFillStyle("#e93d3d");
                        ctx.font = "normal bold 20px sans-serif";
                        ctx.fillText("抢购价:￥", 150 * that.data.rpx, 540 * that.data.rpx);
                        ctx.setFillStyle("#e93d3d");
                        ctx.font = "normal bold 24px sans-serif";
                        ctx.fillText(that.data.details.low_price, 240 * that.data.rpx, 540 * that.data.rpx);
                        ctx.setFillStyle("#333");
                        ctx.font = "normal bold 15px sans-serif";
                        ctx.fillText("团长：" + leaderinfo_name, 150 * that.data.rpx, 567 * that.data.rpx);
                        ctx.fillText("社区：" + leaderinfo_other, 150 * that.data.rpx, 592 * that.data.rpx);
                        that.dealWords({
                            ctx: ctx,
                            font: "normal bold 15px sans-serif",
                            FillStyle: "#333",
                            word: "地址：" + leaderinfo_title,
                            maxWidth: 200 * that.data.rpx,
                            x: 150 * that.data.rpx,
                            y: 597 * that.data.rpx,
                            maxLine: 2
                        });
                        ctx.draw(false, () => {
                            that.canvasToImage(ctx);
                        });
                    }
                });
            }
        });
    },
    killPost_type3: function(ctx, qc) {
        let that = this;
        let leaderinfo_title = that.data.myleaderinfo.title ? that.data.myleaderinfo.title : "-";
        let leaderinfo_name = that.data.myleaderinfo.name ? that.data.myleaderinfo.name : "-";
        let leaderinfo_other = that.data.myleaderinfo.other ? that.data.myleaderinfo.other : "-";
        let leaderinfo_img = that.data.myleaderinfo.other ? that.data.myleaderinfo.img : "/images/default.png";
        wx.getImageInfo({
            src: that.data.details.icon,
            success(res) {
                ctx.drawImage(res.path, 12 * that.data.rpx, 70 * that.data.rpx, 350 * that.data.rpx, 350 * that.data.rpx);
                that.dealWords({
                    ctx: ctx,
                    font: "normal bold 16px sans-serif",
                    FillStyle: "#333",
                    word: that.data.details.name,
                    maxWidth: 350 * that.data.rpx,
                    x: 22 * that.data.rpx,
                    y: 430 * that.data.rpx,
                    maxLine: 1
                });
                ctx.setFillStyle("#fe3112");
                ctx.font = "normal bold 16px sans-serif";
                ctx.fillText("￥", 22 * that.data.rpx, 480 * that.data.rpx);
                ctx.setFillStyle("#fe3112");
                ctx.font = "normal bold 18px sans-serif";
                ctx.fillText(that.data.details.low_price, 38 * that.data.rpx, 480 * that.data.rpx);
                var low_price_width = ctx.measureText(that.data.details.low_price).width;
                ctx.setFillStyle("#969696");
                ctx.font = "normal bold 12px sans-serif";
                ctx.fillText("￥", 40 * that.data.rpx + low_price_width, 480 * that.data.rpx);
                ctx.setFillStyle("#969696");
                ctx.font = "normal bold 14px sans-serif";
                ctx.fillText(that.data.details.low_oprice, 52 * that.data.rpx + low_price_width, 480 * that.data.rpx);
                var low_oprice_width = ctx.measureText(that.data.details.low_oprice).width;
                ctx.beginPath();
                ctx.setStrokeStyle("#969696");
                ctx.setLineWidth(1.5 * that.data.rpx);
                ctx.moveTo(52 * that.data.rpx + low_price_width, 475 * that.data.rpx);
                ctx.lineTo(52 * that.data.rpx + low_price_width + low_oprice_width, 475 * that.data.rpx);
                ctx.stroke();
                ctx.closePath();
                ctx.drawImage(that.data.domain + "/img/mainPack/kill_title.png", 22 * that.data.rpx, 500 * that.data.rpx, 64 * that.data.rpx, 14 * that.data.rpx);
                //that.drawFill(100 * that.data.rpx, 510 * that.data.rpx, 200 * that.data.rpx, 18 * that.data.rpx, 9 * that.data.rpx, '#ee4931', 'fill', ctx);
                                ctx.setFillStyle("#ee4931");
                ctx.font = "12px sans-serif";
                ctx.fillText(that.data.start_at_h + "点" + that.data.start_at_m + "分开始开抢", 100 * that.data.rpx, 513 * that.data.rpx);
                wx.getImageInfo({
                    src: qc,
                    success(res) {
                        that.dealWords({
                            ctx: ctx,
                            font: "normal bold 16px sans-serif",
                            FillStyle: "#d0ffdb",
                            word: "小区团长：" + leaderinfo_name + "-" + leaderinfo_other,
                            maxWidth: 250 * that.data.rpx,
                            x: 22 * that.data.rpx,
                            y: 570 * that.data.rpx,
                            maxLine: 1
                        });
                        ctx.drawImage(that.data.domain + "/img/mainPack/address_icon_blue.png", 22 * that.data.rpx, 602 * that.data.rpx, 9 * that.data.rpx, 11 * that.data.rpx);
                        that.dealWords({
                            ctx: ctx,
                            font: "normal bold 11px sans-serif",
                            FillStyle: "#d0ffdb",
                            word: "自提地址：" + leaderinfo_title,
                            maxWidth: 220 * that.data.rpx,
                            x: 35 * that.data.rpx,
                            y: 595 * that.data.rpx,
                            maxLine: 2
                        });
                        ctx.arc(325 * that.data.rpx, 605 * that.data.rpx, 45 * that.data.rpx, 0, 2 * Math.PI);
                        ctx.setFillStyle("#fff");
                        ctx.fill();
                        ctx.drawImage(res.path, 280 * that.data.rpx, 560 * that.data.rpx, 90 * that.data.rpx, 90 * that.data.rpx);
                        ctx.draw(false, () => {
                            that.canvasToImage(ctx);
                        });
                    }
                });
            }
        });
    },
    killPost_type4: function(ctx, qc) {
        let that = this;
        let leaderinfo_title = that.data.myleaderinfo.title ? that.data.myleaderinfo.title : "-";
        let leaderinfo_name = that.data.myleaderinfo.name ? that.data.myleaderinfo.name : "-";
        let leaderinfo_other = that.data.myleaderinfo.other ? that.data.myleaderinfo.other : "-";
        let leaderinfo_img = that.data.myleaderinfo.other ? that.data.myleaderinfo.img : "/images/default.png";
        wx.getImageInfo({
            src: that.data.details.icon,
            success(res) {
                ctx.drawImage(res.path, 12 * that.data.rpx, 100 * that.data.rpx, 350 * that.data.rpx, 350 * that.data.rpx);
                ctx.drawImage(that.data.domain + "/img/mainPack/kill_type4.png", 12 * that.data.rpx, 330 * that.data.rpx, 350 * that.data.rpx, 120 * that.data.rpx);
                ctx.setFillStyle("#fff");
                ctx.font = "18px sans-serif";
                ctx.fillText("￥", 22 * that.data.rpx, 440 * that.data.rpx);
                ctx.setFillStyle("#fff");
                ctx.font = "24px sans-serif";
                ctx.fillText(that.data.details.low_price, 40 * that.data.rpx, 440 * that.data.rpx);
                var low_price_width = ctx.measureText(that.data.details.low_price).width;
                // ctx.setFillStyle("#fff")
                // ctx.font = "12px sans-serif"
                // ctx.fillText('原价:', 50 * that.data.rpx + low_price_width, 440 * that.data.rpx);
                // ctx.setFillStyle("#fff")
                // ctx.font = "8px sans-serif"
                // ctx.fillText('￥', 80 * that.data.rpx + low_price_width, 440 * that.data.rpx);
                                ctx.setFillStyle("#fff");
                ctx.font = "12px sans-serif";
                ctx.fillText(that.data.details.low_oprice, 92 * that.data.rpx + low_price_width, 440 * that.data.rpx);
                var low_oprice_width = ctx.measureText(that.data.details.low_oprice).width;
                ctx.beginPath();
                ctx.setStrokeStyle("#fff");
                ctx.setLineWidth(1 * that.data.rpx);
                ctx.moveTo(92 * that.data.rpx + low_price_width, 435 * that.data.rpx);
                ctx.lineTo(92 * that.data.rpx + low_price_width + low_oprice_width, 435 * that.data.rpx);
                ctx.stroke();
                ctx.closePath();
                ctx.drawImage(that.data.domain + "/img/mainPack/kill_limit.png", 110 * that.data.rpx, 410 * that.data.rpx, 47 * that.data.rpx, 15 * that.data.rpx);
                ctx.setFillStyle("#fff");
                ctx.font = "9px bold";
                ctx.fillText("限量" + that.data.details.all_stock_number + "份", 112 * that.data.rpx, 420 * that.data.rpx);
                ctx.setFillStyle("#ec2e08");
                ctx.font = "normal bold 18px sans-serif";
                ctx.fillText("限时秒杀", 265 * that.data.rpx, 385 * that.data.rpx);
                ctx.setFillStyle("#ec2e08");
                ctx.font = "11px sans-serif";
                ctx.fillText("开抢时间", 275 * that.data.rpx, 410 * that.data.rpx);
                ctx.setFillStyle("#464144");
                ctx.fillRect(260 * that.data.rpx, 425 * that.data.rpx, 20 * that.data.rpx, 20 * that.data.rpx);
                ctx.fill();
                ctx.setFillStyle("#fff");
                ctx.font = "12px sans-serif";
                ctx.fillText(that.data.start_at_h, 263 * that.data.rpx, 440 * that.data.rpx);
                ctx.setFillStyle("#464144");
                ctx.font = "12px sans-serif";
                ctx.fillText(":", 284 * that.data.rpx, 440 * that.data.rpx);
                ctx.setFillStyle("#464144");
                ctx.fillRect(292 * that.data.rpx, 425 * that.data.rpx, 20 * that.data.rpx, 20 * that.data.rpx);
                ctx.fill();
                ctx.setFillStyle("#fff");
                ctx.font = "12px sans-serif";
                ctx.fillText(that.data.start_at_m, 295 * that.data.rpx, 440 * that.data.rpx);
                ctx.setFillStyle("#464144");
                ctx.font = "12px sans-serif";
                ctx.fillText(":", 316 * that.data.rpx, 440 * that.data.rpx);
                ctx.setFillStyle("#ff5f4b");
                ctx.fillRect(326 * that.data.rpx, 425 * that.data.rpx, 20 * that.data.rpx, 20 * that.data.rpx);
                ctx.fill();
                ctx.setFillStyle("#fff");
                ctx.font = "12px sans-serif";
                ctx.fillText(that.data.start_at_s, 329 * that.data.rpx, 440 * that.data.rpx);
                that.dealWords({
                    ctx: ctx,
                    font: "normal bold 16px sans-serif",
                    FillStyle: "#232323",
                    word: that.data.details.name,
                    maxWidth: 340 * that.data.rpx,
                    x: 20 * that.data.rpx,
                    y: 470 * that.data.rpx,
                    maxLine: 1
                });
                ctx.beginPath();
                ctx.setStrokeStyle("#eee");
                ctx.setLineWidth(1);
                ctx.moveTo(20 * that.data.rpx, 540 * that.data.rpx);
                ctx.lineTo(360 * that.data.rpx, 540 * that.data.rpx);
                ctx.stroke();
                ctx.closePath();
                ctx.setFillStyle("#434343");
                ctx.font = "12px sans-serif";
                ctx.fillText("小区团长：" + leaderinfo_name, 62 * that.data.rpx, 590 * that.data.rpx);
                that.dealWords({
                    ctx: ctx,
                    font: "12px sans-serif",
                    FillStyle: "#434343",
                    word: "提货地址：" + leaderinfo_title,
                    maxWidth: 180 * that.data.rpx,
                    x: 62 * that.data.rpx,
                    y: 600 * that.data.rpx,
                    maxLine: 2
                });
                wx.getImageInfo({
                    src: qc,
                    success(res) {
                        ctx.arc(305 * that.data.rpx, 605 * that.data.rpx, 45 * that.data.rpx, 0, 2 * Math.PI);
                        ctx.setFillStyle("#fff");
                        ctx.fill();
                        ctx.drawImage(res.path, 260 * that.data.rpx, 560 * that.data.rpx, 90 * that.data.rpx, 90 * that.data.rpx);
                        if (leaderinfo_img.indexOf("/images/default.png") == -1) {
                            wx.getImageInfo({
                                src: leaderinfo_img,
                                success(res) {
                                    ctx.save();
                                    ctx.arc(32 * that.data.rpx, 596 * that.data.rpx, 16 * that.data.rpx, 0, 2 * Math.PI);
                                    ctx.setFillStyle("#fff");
                                    ctx.clip();
                                    ctx.drawImage(res.path, 20 * that.data.rpx, 580 * that.data.rpx, 32 * that.data.rpx, 32 * that.data.rpx);
                                    ctx.restore();
                                    ctx.draw(false, () => {
                                        that.canvasToImage(ctx);
                                    });
                                }
                            });
                        } else {
                            ctx.draw(false, () => {
                                that.canvasToImage(ctx);
                            });
                        }
                    }
                });
            }
        });
    },
    killPost_type5: function(ctx, qc) {
        let that = this;
        let leaderinfo_title = that.data.myleaderinfo.title ? that.data.myleaderinfo.title : "-";
        let leaderinfo_name = that.data.myleaderinfo.name ? that.data.myleaderinfo.name : "-";
        let leaderinfo_other = that.data.myleaderinfo.other ? that.data.myleaderinfo.other : "-";
        let leaderinfo_img = that.data.myleaderinfo.other ? that.data.myleaderinfo.img : "/images/default.png";
        wx.getImageInfo({
            src: that.data.details.icon,
            success(res) {
                ctx.drawImage(res.path, 13 * that.data.rpx, 170 * that.data.rpx, 350 * that.data.rpx, 350 * that.data.rpx);
                that.dealWords({
                    ctx: ctx,
                    font: "normal bold 18px sans-serif",
                    FillStyle: "#232323",
                    word: that.data.details.name,
                    maxWidth: 335 * that.data.rpx,
                    x: 25 * that.data.rpx,
                    y: 540 * that.data.rpx,
                    maxLine: 1
                });
                // ctx.setFillStyle("#fe3112")
                // ctx.font = "normal bold 20px sans-serif";
                // ctx.fillText('￥' + that.data.details.low_price, 25 * that.data.rpx, 600 * that.data.rpx);
                // ctx.setFillStyle("#969696")
                // ctx.font = "normal bold 14px sans-serif";
                // ctx.fillText('原价：￥' + that.data.details.low_oprice, 100 * that.data.rpx, 600 * that.data.rpx);
                //that.drawFill(13 * that.data.rpx, 70 * that.data.rpx, 345 * that.data.rpx, 95 * that.data.rpx, 47.5 * that.data.rpx, '#f36055', 'fill', ctx);
                                ctx.setFillStyle("#fff");
                ctx.font = "11px sans-serif";
                ctx.fillText("小区团长：" + leaderinfo_name, 70 * that.data.rpx, 110 * that.data.rpx);
                that.dealWords({
                    ctx: ctx,
                    font: "11px sans-serif",
                    FillStyle: "#fff",
                    word: "自提地址：" + leaderinfo_title,
                    maxWidth: 200 * that.data.rpx,
                    x: 70 * that.data.rpx,
                    y: 115 * that.data.rpx,
                    maxLine: 2
                });
                ctx.drawImage(that.data.domain + "/img/mainPack/kill_title.png", 22 * that.data.rpx, 620 * that.data.rpx, 64 * that.data.rpx, 14 * that.data.rpx);
                // that.drawFill(100 * that.data.rpx, 510 * that.data.rpx, 200 * that.data.rpx, 18 * that.data.rpx, 9 * that.data.rpx, '#ee4931', 'fill', ctx);
                                ctx.setFillStyle("#ee4931");
                ctx.font = "14px sans-serif";
                ctx.fillText(that.data.start_at_h + "点" + that.data.start_at_m + "分开始开抢", 100 * that.data.rpx, 633 * that.data.rpx);
                wx.getImageInfo({
                    src: qc,
                    success(res) {
                        ctx.arc(320 * that.data.rpx, 120 * that.data.rpx, 45 * that.data.rpx, 0, 2 * Math.PI);
                        ctx.setFillStyle("#fff");
                        ctx.fill();
                        ctx.drawImage(res.path, 275 * that.data.rpx, 75 * that.data.rpx, 85 * that.data.rpx, 90 * that.data.rpx);
                        if (leaderinfo_img.indexOf("/images/default.png") == -1) {
                            wx.getImageInfo({
                                src: leaderinfo_img,
                                success(res) {
                                    ctx.save();
                                    ctx.arc(41 * that.data.rpx, 116 * that.data.rpx, 16 * that.data.rpx, 0, 2 * Math.PI);
                                    ctx.setFillStyle("#f36055");
                                    ctx.clip();
                                    ctx.drawImage(res.path, 25 * that.data.rpx, 100 * that.data.rpx, 32 * that.data.rpx, 32 * that.data.rpx);
                                    ctx.restore();
                                    ctx.draw(false, () => {});
                                }
                            });
                        } else {
                            ctx.draw(false, () => {
                                that.canvasToImage(ctx);
                            });
                        }
                    }
                });
            }
        });
    },
    killPost_type6: function(ctx, qc) {
        let that = this;
        let leaderinfo_title = that.data.myleaderinfo.title ? that.data.myleaderinfo.title : "-";
        let leaderinfo_name = that.data.myleaderinfo.name ? that.data.myleaderinfo.name : "-";
        let leaderinfo_other = that.data.myleaderinfo.other ? that.data.myleaderinfo.other : "-";
        let leaderinfo_img = that.data.myleaderinfo.other ? that.data.myleaderinfo.img : "/images/default.png";
        wx.getImageInfo({
            src: that.data.details.icon,
            success(res) {
                ctx.drawImage(res.path, 37 * that.data.rpx, 100 * that.data.rpx, 300 * that.data.rpx, 300 * that.data.rpx);
                that.dealWords({
                    ctx: ctx,
                    font: "normal bold 18px sans-serif",
                    FillStyle: "#232323",
                    word: that.data.details.name,
                    maxWidth: 335 * that.data.rpx,
                    x: 37 * that.data.rpx,
                    y: 420 * that.data.rpx,
                    maxLine: 1
                });
                // ctx.setFillStyle("#fe3112")
                // ctx.font = "normal bold 16px sans-serif"
                // ctx.fillText('￥', 37 * that.data.rpx, 470 * that.data.rpx);
                // ctx.setFillStyle("#fe3112")
                // ctx.font = "normal bold 18px sans-serif"
                // ctx.fillText(that.data.details.low_price, 53 * that.data.rpx, 470 * that.data.rpx);
                                ctx.setFillStyle("#969696");
                ctx.font = "14px sans-serif";
                ctx.fillText("原价:", 37 * that.data.rpx, 490 * that.data.rpx);
                ctx.setFillStyle("#969696");
                ctx.font = "12px sans-serif";
                ctx.fillText("￥", 67 * that.data.rpx, 490 * that.data.rpx);
                ctx.setFillStyle("#969696");
                ctx.font = "14px sans-serif";
                ctx.fillText(that.data.details.low_oprice, 79 * that.data.rpx, 490 * that.data.rpx);
                var low_oprice_width = ctx.measureText(that.data.details.low_oprice).width;
                ctx.beginPath();
                ctx.setStrokeStyle("#969696");
                ctx.setLineWidth(1 * that.data.rpx);
                ctx.moveTo(79 * that.data.rpx, 485 * that.data.rpx);
                ctx.lineTo(79 * that.data.rpx + low_oprice_width, 485 * that.data.rpx);
                ctx.stroke();
                ctx.closePath();
                ctx.drawImage(that.data.domain + "/img/mainPack/kill_time.png", 245 * that.data.rpx, 450 * that.data.rpx, 62.5 * that.data.rpx, 14.5 * that.data.rpx);
                ctx.drawImage(that.data.domain + "/img/mainPack/kill_promit.png", 200 * that.data.rpx, 475 * that.data.rpx, 55.5 * that.data.rpx, 17 * that.data.rpx);
                ctx.setStrokeStyle("#5eaf70");
                ctx.strokeRect(200 * that.data.rpx, 475 * that.data.rpx, 145 * that.data.rpx, 17 * that.data.rpx);
                ctx.setFillStyle("#5eaf70");
                ctx.font = "11px sans-serif";
                ctx.fillText(that.data.start_at_h + "点" + that.data.start_at_m + "分开始", 255 * that.data.rpx, 488 * that.data.rpx);
                wx.getImageInfo({
                    src: qc,
                    success(res) {
                        ctx.rect(37 * that.data.rpx, 530 * that.data.rpx, 100 * that.data.rpx, 100 * that.data.rpx);
                        ctx.setFillStyle("#fff");
                        ctx.fill();
                        ctx.drawImage(res.path, 43 * that.data.rpx, 540 * that.data.rpx, 90 * that.data.rpx, 90 * that.data.rpx);
                        that.dealWords({
                            ctx: ctx,
                            font: "normal bold 18px sans-serif",
                            FillStyle: "#434343",
                            word: leaderinfo_name + "-" + leaderinfo_other,
                            maxWidth: 180 * that.data.rpx,
                            x: 160 * that.data.rpx,
                            y: 540 * that.data.rpx,
                            maxLine: 1
                        });
                        ctx.drawImage(that.data.domain + "/img/mainPack/address_icon_red.png", 160 * that.data.rpx, 572 * that.data.rpx, 9 * that.data.rpx, 11 * that.data.rpx);
                        that.dealWords({
                            ctx: ctx,
                            font: "14px sans-serif",
                            FillStyle: "#969696",
                            word: leaderinfo_title,
                            maxWidth: 180 * that.data.rpx,
                            x: 172 * that.data.rpx,
                            y: 565 * that.data.rpx,
                            maxLine: 1
                        });
                        that.drawFill(160 * that.data.rpx, 600 * that.data.rpx, 100 * that.data.rpx, 16 * that.data.rpx, 8 * that.data.rpx, "#ffd1cc", "fill", ctx);
                        ctx.setFillStyle("#363636");
                        ctx.font = "11px sans-serif";
                        ctx.fillText("长按识别二维码", 168 * that.data.rpx, 613 * that.data.rpx);
                        ctx.draw(false, () => {
                            that.canvasToImage(ctx);
                        });
                    }
                });
            }
        });
    },
    /**
   * x,y-左上角点的坐标；width、height-宽高；radius-圆角；color-绘制颜色；type-绘制类型（'fill'和'stroke'）。
   */
    drawFill: function(x, y, width, height, radius, color, type, ctx) {
        ctx.beginPath();
        ctx.moveTo(x, y + radius);
        ctx.lineTo(x, y + height - radius);
        ctx.quadraticCurveTo(x, y + height, x + radius, y + height);
        ctx.lineTo(x + width - radius, y + height);
        ctx.quadraticCurveTo(x + width, y + height, x + width, y + height - radius);
        ctx.lineTo(x + width, y + radius);
        ctx.quadraticCurveTo(x + width, y, x + width - radius, y);
        ctx.lineTo(x + radius, y);
        ctx.quadraticCurveTo(x, y, x, y + radius);
        ctx[type + "Style"] = color || params.color;
        ctx.closePath();
        ctx[type]();
    },
    canvasToImage: function() {
        let that = this;
        wx.canvasToTempFilePath({
            x: 0,
            y: 0,
            width: 375 * that.data.rpx,
            height: 667 * that.data.rpx,
            destWidth: 4 * 375 * that.data.rpx,
            destHeight: 4 * 667 * that.data.rpx,
            canvasId: "firstCanvas",
            fileType: "png",
            quality: 0,
            success: function(res) {
                let url = [];
                url.push(res.tempFilePath);
                wx.previewImage({
                    current: "",
                    // 当前显示图片的http链接
                    urls: url,
                    // 需要预览的图片http链接列表
                    success() {
                        that.setData({
                            killPoster: false,
                            alert1: 0
                        });
                    }
                });
            },
            fail: function(res) {},
            complete: function(res) {}
        }, this);
    },
    //处理文字多出省略号显示
    dealWords: function(options) {
        options.ctx.setFontSize(options.fontSize);
        //设置字体大小
                options.ctx.font = options.font;
        options.ctx.setFillStyle(options.FillStyle);
        //设置字体颜色
                var allRow = Math.ceil(options.ctx.measureText(options.word).width / options.maxWidth);
        //实际总共能分多少行
                var count = allRow >= options.maxLine ? options.maxLine : allRow;
        //实际能分多少行与设置的最大显示行数比，谁小就用谁做循环次数
                var endPos = 0;
        //当前字符串的截断点
                for (var j = 0; j < count; j++) {
            var nowStr = options.word.slice(endPos);
            //当前剩余的字符串
                        var rowWid = 0;
            //每一行当前宽度    
                        if (options.ctx.measureText(nowStr).width > options.maxWidth) {
                //如果当前的字符串宽度大于最大宽度，然后开始截取
                for (var m = 0; m < nowStr.length; m++) {
                    rowWid += options.ctx.measureText(nowStr[m]).width;
                    //当前字符串总宽度
                                        if (rowWid > options.maxWidth) {
                        if (j === options.maxLine - 1) {
                            //如果是最后一行
                            options.ctx.fillText(nowStr.slice(0, m - 1) + "...", options.x, options.y + (j + 1) * 18);
                            //(j+1)*18这是每一行的高度        
                                                } else {
                            options.ctx.fillText(nowStr.slice(0, m), options.x, options.y + (j + 1) * 18);
                        }
                        endPos += m;
                        //下次截断点
                                                break;
                    }
                }
            } else {
                //如果当前的字符串宽度小于最大宽度就直接输出
                options.ctx.fillText(nowStr.slice(0), options.x, options.y + (j + 1) * 18);
            }
        }
    },
    //点击转发和分享海报
    makeposter_ch: function() {
        let that = this;
        var timeID = that.data.timeId;
        var dostr = "";
        var flag = that.data.flag;
        if (timeID) {
            var leader_id_share = that.data.leader_id_share;
            if (flag == 1) {
                dostr = "now";
            } else if (flag == 0) {
                dostr = "before";
            }
        }
        var leaderInfo = that.data.myleaderinfo;
        if (leaderInfo) {
            that.setData({
                alert1: 0
            });
            that.getSharePoster(leaderInfo, timeID, dostr);
        } else {
            wx.showToast({
                title: "缺少团长信息",
                icon: "none"
            });
        }
    },
    //秒杀海报
    getSharePoster(leaderInfo, timeID, dostr) {
        let that = this;
        var details = that.data.details;
        wx.showLoading({
            title: "海报生成中"
        });
        common.request({
            endpoint: "share/poster_seckill",
            method: "post",
            data: {
                id: details.id,
                //商品id
                name: leaderInfo.name,
                //团长姓名    
                gname: leaderInfo.other,
                //团名
                address: leaderInfo.title,
                //收货地址
                lid: leaderInfo.leader_id,
                //团长的用户id  
                price: details.low_price,
                original_price: details.low_oprice,
                time_id: timeID,
                //(秒杀要)
                do: dostr
            },
            success(res) {
                console.log(res);
                res = JSON.parse(res);
                var imgURL = res.extra.image[0].url;
                console.log(imgURL, "url");
                wx.hideLoading();
                if (res.code == 4) {
                    that.setData({
                        sharePosterImgURL: that.data.details.icon
                    });
                } else {
                    var sharePosterImgURL = [];
                    sharePosterImgURL.push(imgURL);
                    wx.previewImage({
                        urls: sharePosterImgURL
                    });
                }
            },
            fail() {
                wx.hideLoading();
            }
        });
    },
    //幻灯片
    swiperChange: function(e) {
        console.log(e.detail.current);
        this.setData({
            currentSwiper: e.detail.current
        });
    },
    //关闭
    close_alert: function(e) {
        this.setData({
            alert: 0
        });
    },
    /** 
   * 添加 sku 属性
   */
    addSkuAttribute: function(e) {
        console.log(e);
        let key_id = parseInt(e.currentTarget.dataset.key_id);
        let value_id = parseInt(e.currentTarget.dataset.value_id);
        let a_key_index = parseInt(e.currentTarget.dataset.a_key_index);
        let a_value_index = parseInt(e.currentTarget.dataset.a_value_index);
        let sku = this.data.sku;
        sku = this.reBlanceSku(sku, key_id, value_id);
        console.log(sku);
        let attribute = this.data.details.sku_attribute;
        attribute = this.selectSku(attribute, a_key_index, a_value_index);
        let sku_info = this.getProductBySku(this.data.details.sku, sku);
        this.setData({
            sku: sku,
            ["details.sku_attribute"]: attribute,
            sku_info: sku_info,
            buy_count: 1
        });
    },
    /** 
   * 重平衡 sku
   * key_id: integer
   */
    reBlanceSku: function(sku, key_id, value_id) {
        let sku_lib = sku != "" ? this.splitSku(sku) : [];
        sku_lib = this.addSku(sku_lib, {
            key_id: key_id,
            value_id: value_id
        });
        sku_lib = this.sortSku(sku_lib);
        return this.buildSku(sku_lib);
    },
    /** 
   * 重建 sku
   */
    buildSku: function(sku_lib) {
        return sku_lib.map(item => {
            return item.key_id + "," + item.value_id;
        }).join("|");
    },
    /** 
   * 对选择的 sku 属性进行排序
   */
    sortSku: function(sku_lib) {
        return sku_lib.sort((pre, next) => {
            if (pre.key_id > next.key_id) {
                return 1;
            } else if (pre.key_id < next.key_id) {
                return -1;
            } else {
                return 0;
            }
        });
    },
    /** 
   * 分割现有 sku 成对象数组
   */
    splitSku: function(sku) {
        return sku.split("|").map(sku_tmp => {
            let [key, value] = sku_tmp.split(",");
            const t = {};
            t.key_id = parseInt(key);
            t.value_id = parseInt(value);
            return t;
        });
    },
    /** 
   * 添加一个 sku
   */
    addSku: function(sku_lib, sku) {
        let t = sku_lib.filter(item => {
            if (item.key_id === sku.key_id) {
                return false;
            }
            return true;
        });
        t.push(sku);
        return t;
    },
    /** 
   * 选择 sku
   */
    selectSku: function(attribues, a_index, v_index = 0) {
        console.log(attribues);
        console.log(a_index);
        console.log(attribues[a_index]);
        if (attribues[a_index]) {
            let values = attribues[a_index].attribute_value;
            values = values.map(item => {
                item.selected = false;
                return item;
            });
            values[v_index].selected = true;
            attribues[a_index].attribute_value = values;
        }
        return attribues;
    },
    /** 
   * 选择单个 sku 属性
   */
    selectSingleSku: function(attribute_value, v_index = 0) {
        attribute_value.map(item => {
            item.selected = false;
            return item;
        });
        attribute_value[v_index].selected = true;
        return attribute_value;
    },
    /**
   * 根据 sku 获取物品
   */
    getProductBySku: function(sku_products, sku) {
        return sku_products[sku];
    },
    save_count: function(e) {
        parseInt;
        this.setData({
            buy_count: parseInt(e.detail.value)
        });
    },
    blur: function(e) {
        let count = e.detail.value;
        if (count <= 0) {
            count = 1;
        }
        this.setData({
            buy_count: parseInt(count)
        });
    },
    reduce_count: function() {
        let buy_count = this.data.buy_count;
        if (buy_count > 1) {
            buy_count--;
        }
        this.setData({
            buy_count: buy_count
        });
    },
    add_count: function(e) {
        let that = this;
        that.add_count_ch(e);
        if (that.data.subscribeMessage) {
            wx.requestSubscribeMessage({
                tmplIds: that.data.tmplIds,
                success(res) {},
                fail(err) {
                    console.log(err);
                }
            });
        }
    },
    add_count_ch: function(e) {
        console.log("每个产品的信息");
        console.log(e);
        let that = this;
        let buy_count = this.data.buy_count;
        let restrictions = e.currentTarget.dataset.restrictions;
        let pro_limit = that.data.sku_info.pro_limit;
        if (pro_limit == 0) {
            buy_count++;
        } else {
            if (buy_count >= pro_limit) {
                wx.showModal({
                    title: "提示",
                    content: "本商品限购" + pro_limit + "份"
                });
            } else {
                buy_count++;
            }
        }
        this.setData({
            buy_count: buy_count
        });
    },
    join_goods: function() {
        var that = this;
        var alert = that.data.alert;
        if (alert == 0) {
            this.setData({
                alert: 1,
                btn_true: 1
            });
        } else {
            var cart_count = wx.getStorageSync("cart_count") || 0;
            var details = that.data.details;
            var sku_info = that.data.sku_info;
            var buy_count = that.data.buy_count;
            var id = that.data.product_id;
            cart_count = cart_count + buy_count;
            var cart = wx.getStorageSync("cart") || [];
            if (cart_count <= 99999) {
                if (sku_info.stock_number >= buy_count) {
                    if (cart == "") {
                        let goods = {
                            id: sku_info.item_id,
                            product_id: id,
                            img: details.icon_img,
                            title: details.name,
                            varieties: sku_info.title,
                            price: sku_info.price,
                            o_price: sku_info.o_price,
                            count: buy_count,
                            stock_number: sku_info.stock_number,
                            select: 1,
                            proID: id,
                            status: 1
                        };
                        wx.showToast({
                            title: "加入购物车成功",
                            icon: "success",
                            success: res => {
                                wx.setStorage({
                                    key: "cart_count",
                                    data: cart_count
                                });
                                this.setData({
                                    cart_count: cart_count
                                });
                                // setTimeout(() => {
                                                                var cart = wx.getStorageSync("cart") || that.data.cart;
                                cart.push(goods);
                                wx.setStorage({
                                    key: "cart",
                                    data: cart
                                });
                                that.setData({
                                    buy_count: 1,
                                    alert: 0
                                });
                                // }, 500)
                                                        }
                        });
                    } else {
                        var total = 0;
                        var index = 0;
                        for (var i = 0; i < cart.length; i++) {
                            if (sku_info.item_id != cart[i]["id"]) {
                                total++;
                            } else {
                                index = i;
                                break;
                            }
                        }
                        if (total == cart.length) {
                            let goods = {
                                id: sku_info.item_id,
                                product_id: id,
                                img: details.icon_img,
                                title: details.name,
                                varieties: sku_info.title,
                                price: sku_info.price,
                                o_price: sku_info.o_price,
                                count: buy_count,
                                stock_number: sku_info.stock_number,
                                select: 1,
                                proID: id,
                                status: 1
                            };
                            wx.showToast({
                                title: "加入购物车成功",
                                icon: "success",
                                success: res => {
                                    wx.setStorage({
                                        key: "cart_count",
                                        data: cart_count
                                    });
                                    this.setData({
                                        cart_count: cart_count
                                    });
                                    // setTimeout(() => {
                                                                        var cart = wx.getStorageSync("cart") || that.data.cart;
                                    cart.push(goods);
                                    wx.setStorage({
                                        key: "cart",
                                        data: cart
                                    });
                                    that.setData({
                                        buy_count: 1,
                                        alert: 0
                                    });
                                    // }, 500)
                                                                }
                            });
                        } else {
                            cart[index]["count"] = cart[index]["count"] + buy_count;
                            wx.showToast({
                                title: "加入购物车成功",
                                icon: "success",
                                success: res => {
                                    wx.setStorage({
                                        key: "cart_count",
                                        data: cart_count
                                    });
                                    this.setData({
                                        cart_count: cart_count
                                    });
                                    // setTimeout(() => {
                                                                        wx.setStorage({
                                        key: "cart",
                                        data: cart
                                    });
                                    that.setData({
                                        buy_count: 1,
                                        alert: 0
                                    });
                                    // }, 500)
                                                                }
                            });
                        }
                    }
                } else {
                    wx.showToast({
                        title: "加入购物车失败",
                        icon: "none"
                    });
                }
            } else {
                wx.showToast({
                    title: "购物车最多加99999个商品！",
                    icon: "none"
                });
            }
        }
    },
    buy: function() {
        var that = this;
        var alert = that.data.alert;
        console.log("----------------------------------------------------");
        console.log(that.data.sku_info);
        common.getUserInfoNew({
            success() {
                if (alert == 0) {
                    that.setData({
                        alert: 1,
                        btn_true: 2
                    });
                } else {
                    that.buy_ch();
                    if (that.data.subscribeMessage) {
                        wx.requestSubscribeMessage({
                            tmplIds: that.data.tmplIds,
                            success(res) {},
                            fail(err) {
                                console.log(err);
                            }
                        });
                    }
                }
            }
        });
    },
    buy_ch: function() {
        let that = this;
        var alert = that.data.alert;
        var details = that.data.details;
        var sku_info = that.data.sku_info;
        var buy_count = that.data.buy_count;
        var id = that.data.goodsId;
        var sku_id = sku_info.item_id;
        let sku_item = sku_info.item_id + "," + buy_count + "," + sku_info.credit_sent + "," + details.only_express;
        var timeId = that.data.timeId;
        console.log(sku_item);
        let pro_limit = sku_info.pro_limit;
        if (pro_limit != 0 && buy_count > pro_limit) {
            wx.showModal({
                title: "提示",
                content: "本商品限购" + pro_limit + "份"
            });
            return false;
        }
        if (sku_info.stock_number >= buy_count) {
            wx.navigateTo({
                url: "/newPlace_order/pages/newPlace_order/newPlace_order?sku_item=" + sku_item + "&status=" + 0 + "&time_id=" + timeId + "&isseckill=1"
            });
        } else {
            wx.showToast({
                title: "库存不足",
                icon: "none"
            });
        }
    },
    //获取tmplIds
    getTmplIds: function() {
        let that = this;
        common.request({
            endpoint: "set/template_get",
            method: "post",
            data: {},
            header: {
                "content-type": "application/json"
            },
            success: res => {
                console.log(res);
                let tmplIds = [];
                let subscribeMessage = true;
                res.extra.map(v => {
                    if ((v.type == "21" || v.type == "22" || v.type == "23") && v.status == "1") {
                        tmplIds.push(v.template_id);
                    }
                });
                if (!tmplIds.length) {
                    subscribeMessage = false;
                }
                that.setData({
                    tmplIds: tmplIds,
                    subscribeMessage: subscribeMessage
                });
            }
        });
    }
});